define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'broadcast/broadcastai/index' + location.search,
                    add_url: 'broadcast/broadcastai/add',
                    del_url:'broadcast/broadcastai/del',
                    multi_url: 'broadcast/broadcastai/multi',
                    import_url: 'broadcast/broadcastai/import',
                    table: 'broadcast_ai',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                //pk: 'id',
                sortName: 'id',
                sortOrder:'desc',
                search: false, //是否启用快速搜索
                commonSearch: true, //是否启用通用搜索
                searchFormVisible: true, //是否始终显示搜索表单
                clickToSelect: false, //是否启用点击选中
                dblClickToEdit: false, //是否启用双击编辑
                singleSelect: true, //是否启用单选
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'broadcast_id', title: __('直播主题'),visible:false,searchList:$.getJSON('broadcast/broadcastai/searchlist')},
                        {field: 'image', title: '图片',events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'broadcast.title', title: __('直播主题'),operate: false},
                        {field: 'remark', title: __('备注'),operate: false},
                        {field: 'createtime', title: __('Createtime'), operate: false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate: false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 
                        buttons:[
                            {
                                name: 'faarrowdown',
                                title: __('全量下载'),
                                classname: 'btn btn-xs btn-warning',
                                icon: 'fa fa-arrow-circle-o-down',
                                url: function (row) {
                                    return "/index/index/download3?id="+row.id;
                                },
                                extend:' target="_blank"',
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    if(row.status == '2'){
                                        return true;
                                    }
                                    return false;
                                    
                                }
                            },
                            {
                                name: 'detail',
                                title: __('查看'),
                                classname: 'btn btn-xs btn-warning btn-dialog',
                                icon: 'fa fa-list',
                                url: function (row) {
                                    return "/root.php/broadcast/broadcastai/detail?ids="+row.id;
                                },
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    if(row.status == 2){
                                        return true;
                                    }
                                    return false;
                                    
                                }
                            },
                        ],
                        formatter: Table.api.formatter.operate}
                    ]
                ]
                
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
